package com.hxd.otc.widget;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.view.View;

import com.hxd.otc.R;
import com.hxd.otc.dialog.MultipleBlocksDialog;
import com.hxd.otc.module.my.activity.ModifyMoneyPasswordActivity;

/**
 * 包  名 :  com.hxd.otc.widget
 * 类  名 :  WalletDialogTipsUtil
 * 作  者 :  卫广玉
 * 时  间 :  2018/6/11 15:51
 * 描  述 :  ${TODO}
 */
public class WalletDialogTipsUtil {
    //camera 权限
    public static void showCameraTipsDialog(final Activity activity) {
        final MultipleBlocksDialog dailog = new MultipleBlocksDialog(activity);
        dailog.setContent(activity.getString(R.string.wallet_permission_camera_tips));
        dailog.setTitle(activity.getString(R.string.wallet_permission_camera_title));
        dailog.setTvCancle(activity.getString(R.string.cancel));
        dailog.setTvSure(activity.getString(R.string.wallet_common_ok), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dailog.dismiss();
                activity.startActivity(getAppDetailSettingIntent(activity));

            }
        });
        dailog.show();
    }

    //存储权限
    public static void showExternalTipsDialog(final Activity activity) {
        final MultipleBlocksDialog dailog = new MultipleBlocksDialog(activity);
        dailog.setContent(activity.getString(R.string.wallet_permission_external_tips));
        dailog.setTitle(activity.getString(R.string.wallet_permission_external_title));
        dailog.setTvCancle(activity.getString(R.string.cancel));
        dailog.setTvSure(activity.getString(R.string.wallet_common_ok), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dailog.dismiss();
                activity.startActivity(getAppDetailSettingIntent(activity));

            }
        });
        dailog.show();
    }


    //设置交易密码提示
    public static void showTpwTipsDialog(final Activity activity) {
        final MultipleBlocksDialog dailog = new MultipleBlocksDialog(activity);
        dailog.setContent(activity.getString(R.string.wallet_tpw_dialog_content));
        dailog.setTitle(activity.getString(R.string.wallet_tpw_dialog_title));
        dailog.setTvCancle(activity.getString(R.string.cancel));
        dailog.setTvSure(activity.getString(R.string.wallet_common_ok), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dailog.dismiss();
                Intent intent = new Intent(activity, ModifyMoneyPasswordActivity.class);
                activity.startActivity(intent);
            }
        });
        dailog.show();
    }

    //普通弹窗
    public static void showTipsDialog(final Activity activity, String title, String content) {
        final MultipleBlocksDialog dailog = new MultipleBlocksDialog(activity);
        dailog.setContent(content);
        dailog.setTitle(title);
        dailog.show();
    }

    private static Intent getAppDetailSettingIntent(final Activity activity) {
        Intent localIntent = new Intent();
        localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (Build.VERSION.SDK_INT >= 9) {
            localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
            localIntent.setData(Uri.fromParts("package", getPackageName(activity), null));
        } else if (Build.VERSION.SDK_INT <= 8) {
            localIntent.setAction(Intent.ACTION_VIEW);
            localIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
            localIntent.putExtra("com.android.settings.ApplicationPkgName", getPackageName(activity));
        }
        return localIntent;
    }


    private static String getPackageName(Activity context) {
        try {
            PackageManager packageManager = context.getPackageManager();
            PackageInfo packageInfo = packageManager.getPackageInfo(
                    context.getPackageName(), 0);
            return packageInfo.packageName;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
